//
//  AppDelegate.m
//  ProjectForCustomer
//
//  Created by 钟游 on 2019/8/24.
//  Copyright © 2019年 钟游. All rights reserved.
//

#import "AppDelegate.h"
#import "LoginController.h"
#import "AdvertisementController.h"
#import <UMShare/UMShare.h>
#import <UMCommon/UMCommon.h>
#import "CustomBar.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [self setupDefaultUI];
    [self onAddLaunchViewForWindom];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.window.rootViewController=[[  UINavigationController alloc]initWithRootViewController: [[AdvertisementController alloc]init]];
    });

    [UMConfigure initWithAppkey:@"5d63e8593fc195b5410008a6" channel:@"App Store"];
    [self configUSharePlatforms];
    [self confitUShareSettings];
    return YES;
}

- (void)confitUShareSettings
{
    /*
     * 打开图片水印
     */
    //[UMSocialGlobal shareInstance].isUsingWaterMark = YES;
    /*
     * 关闭强制验证https，可允许http图片分享，但需要在info.plist设置安全域名
     <key>NSAppTransportSecurity</key>
     <dict>
     <key>NSAllowsArbitraryLoads</key>
     <true/>
     </dict>
     */
    //[UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
}
- (void)configUSharePlatforms
{
    /* 设置微信的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx983729df34d4b9be" appSecret:@"8b07c611e8639f8bb34dd764f23042e4" redirectURL:@"http://mobile.umeng.com/social"];
    /*
     * 移除相应平台的分享，如微信收藏
     */
    //[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
    /* 设置分享到QQ互联的appID
     * U-Share SDK为了兼容大部分平台命名，统一用appKey和appSecret进行参数设置，而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"101728228"/*设置QQ平台的appID*/  appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
    /* 设置新浪的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"1428615272"  appSecret:@"36a3eb5d52ff291c523da82652844e56" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
    /* 钉钉的appKey */
 
    /* 支付宝的appKey */
    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_AlipaySession appKey:@"2015111700822536" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
  
 
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}

- (void)setupDefaultUI {
    if(IOS7){
        [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
        //      [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:88/255.0 green:144/255.0 blue:216/255.0 alpha:1.0f]];
        [[UINavigationBar appearance] setBarTintColor:WYColorMainBar];
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
        [[UITabBar appearance] setTintColor:[UIColor colorWithRed:88/255.0 green:144/255.0 blue:216/255.0 alpha:1.0f]];
        //      [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];//设置导航栏前景色为白色／／默认的黑色（UIStatusBarStyleDefault）就是电池和网络状态的
        [UIApplication sharedApplication].windows.firstObject.backgroundColor=WYColorBackgroundView;
        
        
        //    UIPageControl * pageControl = [ UIPageControl appearance ] ;
        //    pageControl.pageIndicatorTintColor = [ UIColor lightGrayColor ] ;
        //    pageControl.currentPageIndicatorTintColor = [ UIColor blackColor ] ;
        //    pageControl.backgroundColor = [ UIColor whiteColor ] ;
        
    }
    else
    {
        [[CustomBar appearance] setBackgroundColor:WYColorMainBar];
        [[CustomBar appearance] setTintColor:[UIColor whiteColor]];
    }
}
-(void)onAddLaunchViewForWindom{
    UIViewController *mianViewCtrl = [[UIViewController alloc]init];
    self.window.rootViewController = mianViewCtrl;
    
    UIImageView *_mainImgView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _mainImgView.backgroundColor = [UIColor whiteColor];
    _mainImgView.contentMode = UIViewContentModeScaleToFill;
    [mianViewCtrl.view addSubview:_mainImgView];
    
    NSDictionary *infoDic = [[NSBundle mainBundle]infoDictionary];
    CGSize mainSize = [UIScreen mainScreen].bounds.size;
    
    NSArray *UILaunchImages = [infoDic objectForKey:@"UILaunchImages"];
    for (NSDictionary *dic in UILaunchImages) {
        NSString *imgSize = [NSString stringWithFormat:@"%@",[dic objectForKey:@"UILaunchImageSize"]];
        if ([imgSize isEqualToString:NSStringFromCGSize(mainSize)]) {
            NSString *UILaunchImageName = [NSString stringWithFormat:@"%@",[dic objectForKey:@"UILaunchImageName"]];
            _mainImgView.image = [UIImage imageNamed:UILaunchImageName];
        }
    }
    NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"首页加载" withExtension:@"gif"];
    //将GIF图片转换成对应的图片源
    CGImageSourceRef gifSource = CGImageSourceCreateWithURL((CFURLRef) fileUrl, NULL);
    //获取其中图片源个数，即由多少帧图片组成
    size_t frameCount = CGImageSourceGetCount(gifSource);
    //定义数组存储拆分出来的图片
    NSMutableArray *frames = [[NSMutableArray alloc] init];
    for (size_t i = 0; i < frameCount; i++) {
        //从GIF图片中取出源图片
        CGImageRef imageRef = CGImageSourceCreateImageAtIndex(gifSource, i, NULL);
        //将图片源转换成UIimageView能使用的图片源
        UIImage *imageName = [UIImage imageWithCGImage:imageRef];
        //将图片加入数组中
        [frames addObject:imageName];
        CGImageRelease(imageRef);
    }
    UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:CGRectMake(KscreenWidth*0.5-15, 110, 60, 60)];
    //将图片数组加入UIImageView动画数组中
    gifImageView.animationImages = frames;
    //每次动画时长
    gifImageView.animationDuration = 1.3;
    //开启动画，此处没有调用播放次数接口，UIImageView默认播放次数为无限次，故这里不做处理
    [gifImageView startAnimating];
    [mianViewCtrl.view addSubview:gifImageView];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
